# Copyright (C) 2010 Iain Surgey.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

import sys
import os.path
import re

class File:
	def __init__(self,filename):
		self.name = filename
		self.line = 0
		self.file = None
		self.comment = False
		self.defs = False
		self.init = False
		
		if not os.path.exists(filename):
			print "File Error : File not found. [%s]" % self.name
			sys.exit()
		
		try:
			self.file = open(self.name, "r")
		except:
			print "File Error : Cannot open file for read. [%s]" % self.name
			sys.exit()
	
		print "Opened file : "+self.name
		
	def read(self):
		self.line = self.line + 1
		return self.file.readline()
			
			
class Var():
	def __init__(self,name,type):
		self.name = name
		self.type = type
		self.ptr = 0
		self.arr = []
		self.len = 0
		self.ofs = 0
		self.atotal = 1
		self.line = 0
		self.file = None
		self.inl = False
		

class Macro():
	def __init__(self,name,value):
		self.name = name
		self.value = value
		self.re = re.compile("[^a-zA-Z0-9_]("+self.name+")[^a-zA-Z0-9_]")
		

class Type():
	def __init__(self,name,length=0,htype=None):
		
		self.name = name
		self.len = length
		self.line = 0
		self.varacc = ""
		self.file = None
		
		if htype == None:
			self.vars = {}
			self.vlist = []
			self.complete = False
			self.basic = False
		else:
			self.htype = htype
			self.complete = True
			self.basic = True
	

class Varacc():
	def __init__(self,name,actype):
		self.name = name
		self.arrli = []
		
